﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Management.Instrumentation;
using System.IO;

namespace Tzync
{
    public class Utility
    {
        //Description     : Function to get the CPUID                    
        public static String GetCPUId()
        {
            String motherBoardID = "";
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Product FROM Win32_BaseBoard");
            // Executing the query...
            // Because the machine has a single Motherborad, then a single object (row) returned.

            ManagementObjectCollection information = searcher.Get();
            foreach (ManagementObject obj in information)
            {
                // Retrieving the properties (columns)    
                // Writing column name then its value    
                foreach (PropertyData data in obj.Properties)
                    motherBoardID = data.Value.ToString();
            }
            // For typical use of disposable objects enclose it in a using statement instead.
            searcher.Dispose();
            return motherBoardID;
        }

        //Description     : Function to calculate the size of a directory
        //Pre-Conditions  : directory is not NULL
        //Post-Conditions : size of the directory is calculated.

        public static long CalculateDirectorySize(DirectoryInfo directory)
        {
            long totalSize = 0;

            // Examine all contained files.
            FileInfo[] files = directory.GetFiles();
            foreach (FileInfo file in files)
            {
                totalSize += file.Length;
            }

            DirectoryInfo[] dirs = directory.GetDirectories();
            foreach (DirectoryInfo dir in dirs)
            {
                totalSize += CalculateDirectorySize(dir);
            }

            return totalSize;
        }
    }
}
